/**
 * @param {string} s
 * @return {number}
 */
var minAddToMakeValid = function(s) {
  let left = 0, right = 0;
  for(let i = 0; i < s.length; i++) {
    if(s[i] == "(") {
      left++;
    } else {
      if(left) left--;
      else right++;
    }
  }
  return left + right;
};
let s = "())";
console.log(minAddToMakeValid(s));
s = "(((";
console.log(minAddToMakeValid(s));
